﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace MvcPompling.Models.Database
{
    public class SqlServerPomplingProperties
    {
        internal void SaveProperty(WebProperty property)
        {

            using (SqlConnection conn = new SqlConnection(Globals.GetConnectionString()))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    Address a = (Address)property;
                    property.AddressLine1 = "Test 1";
                    property.AddressLine2 = "Test line 2";
                    property.City = "TestCity";
                    property.County = "Lancashire";
                    property.DateAdded = DateTime.Now;
                    property.DayOfMonthAdded = DateTime.Now.Day;
                    property.LongDescription = "Long description";
                    property.MonthAdded = DateTime.Now.Month;
                    property.YearAdded = DateTime.Now.Year;

                    cmd.CommandText = "INSERT INTO Addresses (AddressLine1, AddressLine2) VALUES ('" + property.AddressLine1 + "', '" + property.AddressLine2 + "' )";
                    cmd.Connection = conn;
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
            }

        }
    }
}